package com.oda.camera.util;

import java.util.ArrayList;
import java.util.List;

import com.activity.colza.R;
import com.activity.colza.R.drawable;
import com.activity.colza.R.id;
import com.activity.colza.R.layout;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MyAdapter extends BaseAdapter {
	
	private List<Item> items = new ArrayList<Item>();
    private LayoutInflater inflater;
    
    
    /**
     * 
     * @param context the application's context 
     */
    public MyAdapter(Context context,BitmapFactory.Options bmOptions, PathFile imageList) {
        inflater = LayoutInflater.from(context);
        try {
        	if(imageList.size()!=0){
            	for(String s:imageList){       		
            			Bitmap bitmapImage = BitmapFactory.decodeFile(s, bmOptions);
                    	items.add(new Item("im", R.drawable.ic_action_user, bitmapImage));
                }
            }
		} catch (Exception e) {
			Log.d("LIST", "List of link 0"+e);
			items.add(new Item("oda", R.drawable.ic_action_user, null));
		}
//        if(imageList.size()!=0){
//        	for(String s:imageList){       		
//        			Bitmap bitmapImage = BitmapFactory.decodeFile(s, bmOptions);
//                	items.add(new Item("im", R.drawable.ic_action_user, bitmapImage));
//            }
//        }
//        else{
//        	Log.d("LIST", "List of link 0");
//        	items.add(new Item("oda", R.drawable.ic_action_user, null));
//        }
        Log.d("HERE", "ADAPTER");
    }

    
	@Override
	public int getCount() {
		return items.size();
	}

	@Override
	public Object getItem(int i) {
		return items.get(i);
	}

	@Override
	public long getItemId(int i) {
		return items.get(i).drawableId;
	}

	@Override
	public View getView(int i, View view, ViewGroup groupview) {
		View v=view;
		ImageView picture;
		TextView name;
		
		if(v == null) {
            v = inflater.inflate(R.layout.test_imageview, groupview, false);
            v.setTag(R.id.picture, v.findViewById(R.id.picture));
            //v.setTag(R.id.text, v.findViewById(R.id.text));
        }
		picture = (ImageView)v.getTag(R.id.picture);
        //name = (TextView)v.getTag(R.id.text);
        Item item = (Item)getItem(i);
        //picture.setImageResource(item.drawableId);
        picture.setImageBitmap(item.imageBitmap);
        //name.setText(item.name);

        return v;
	}
	
	/**
	 * 
	 * @category class Item
	 *
	 */
	private class Item {
        final String name;
        final int drawableId;
        final Bitmap imageBitmap;

        Item(String name, int drawableId,Bitmap imageBitmap) {
            this.name = name;
            this.drawableId = drawableId;
            this.imageBitmap=imageBitmap;
        }
    }

}
